package 二叉树相关问题;

public class 二叉搜索树与双向链表 {
    Node pre,head;
    public Node treeToDoublyList(Node root) {
         if (root==null)
             return root;
         dfs(root);
         head.left=pre;
         pre.right=head;
         return head;
    }

    private void dfs(Node cur) {
        if (cur==null)
            return;
        dfs(cur.left);
        if (pre!=null)
            pre.right=cur;
        else
            head=cur;
        cur.left=pre;
        pre=cur;
        dfs(cur.right);
    }
}
